<?php

class m_detail_faktur extends CI_Model {

    function __construct() {
        parent::__construct();
    }

    public function get($where = null, $id = null, $limit = null, $offset = null) {
        if ($where != null)
            $this->db->where($where, $id);
        if ($limit != null && $offset != null)
            $this->db->limit($limit, $offset);
        $this->db->select("detail_faktur.*");
        $this->db->select("barang.NAMA_BARANG");
        $this->db->join("barang","barang.ID_BARANG = detail_faktur.ID_BARANG");
        return $this->db->get("detail_faktur");
    }

    public function get_all($id = null, $limit = null, $offset = null) {
        if ($where != null)
            $this->db->where($where, $id);
        if ($limit != null && $offset != null)
            $this->db->limit($limit, $offset);
        $this->db->where('ID_FAKTUR',$id);
        return $this->db->get("detail_faktur");
    }

    public function get_detail($where = null, $limit = null, $offset = null) {
        $this->load->model('crud/m_faktur');
        $id_faktur = $this->m_faktur->get_id($where)->row();

        if ($where != null)
            $this->db->where('ID_FAKTUR', $id_faktur->ID_FAKTUR);
        if ($limit != null && $offset != null)
            $this->db->limit($limit, $offset);
        return $this->db->get("detail_faktur");
    }

    function insert($id_faktur) {
        $this->load->model('crud/m_faktur');

        $data = array(
            'ID_BARANG' => $this->input->post('ID_BARANG', TRUE),
            'ID_FAKTUR' => $id_faktur,
            'JUMLAH' => $this->input->post('UNIT', TRUE),
            'HARGA_BELI' => $this->input->post('HARGA_BELI', TRUE),
            'DISKON' => $this->input->post('DISKON', TRUE),
            'PPN' => $this->input->post('PPN', TRUE),
            'TOTAL' => $this->input->post('HARGA', TRUE),
        );
        return $this->db->insert('detail_faktur', $data);
    }

    function deletedetail($iddetailorder) {
        $this->db->where('ID_DETAIL_FAKTUR', $iddetailorder);
        $this->db->delete('detail_faktur');
    }

}
?>
